# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Llewelyn Trahaearn <WoefulDerelict at GMail dot com>
# Contributor: rtfreedman  <rob dot til dot freedman at gmail dot com>
# Contributor: speps <speps at aur dot archlinux dot org> 

pkgbase=rtmidi
pkgname=(
  rtmidi
  rtmidi-docs
)
pkgver=5.0.0
pkgrel=2
pkgdesc="A set of C++ classes that provides a common API for realtime MIDI input/output."
arch=(loong64 x86_64)
url="https://www.music.mcgill.ca/~gary/rtmidi/"
license=(custom:RtMidi)
makedepends=(
  alsa-lib
  doxygen
  gcc-libs
  glibc
  jack
)
source=(https://github.com/thestk/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha512sums=('f154905af9a8a85bf543f88035e8744970afe703ea3b4b2f21d85e246cf841fc86b47fd402a81bef27d4233c0d8ccf51943dc2fa42dfdd5447e1f5c3d6634297')
b2sums=('74a4dac921abf1d6bc102bfd6e4edd3b9dd7fead045ded15c8793168348e330e896af5d87ae4dfa8128baf4de99660a89e191e29b2135d2a446e3fcddb37f53f')

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --with-alsa
    --with-jack
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  # prevent overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_rtmidi() {
  depends=(
    alsa-lib
    gcc-libs
    glibc
    jack
  )
  optdepends=('rtmidi-docs: for documentation')
  provides=(librtmidi.so)

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_rtmidi-docs() {
  pkgdesc+=" - documentation"

  install -vDm 644 $pkgbase-$pkgver/{README.md,doc/release.txt} -t "$pkgdir/usr/share/doc/$pkgbase/"
  install -vDm 644 $pkgbase-$pkgver/doc/html/* -t "$pkgdir/usr/share/doc/$pkgbase/html"
  install -vDm 644 $pkgbase-$pkgver/doc/images/* -t "$pkgdir/usr/share/doc/$pkgbase/images"
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
